package Singleton.demo7;

import java.io.Serializable;

public class Singleton implements Serializable {

    private static   boolean flag=false;
    private Singleton()
    {
        //如果flag为true，就说明不是第一次访问，直接抛出异常,如果为false，就说明是第一次，直接去创建对象
        if (flag)
        {
            throw new RuntimeException();
        }
        flag=true;

    }
    private static  class SingletonHandler
    {
        private static  final Singleton  INSTANCE = new Singleton();
    }

    public static Singleton getInstance()
    {
         return SingletonHandler.INSTANCE;
    }


}
